package com.作业.Day11;

public class OrderingUtil {
    OrderingSet[] orderingSets;
    Dishes[] dishes;

    void initial() {
        OrderingSet[] orderingSets = {
                new OrderingSet("张晴", "红烧带鱼 2份", "3", "天成路207号", "已完成", "76.0"),
                new OrderingSet("张晴", "鱼香肉丝 2份", "10", "天成路207号", "已预定", "45.0"),
                null,
            null
        };
        this.orderingSets = orderingSets;
        Dishes[] dishes = {
                new Dishes("鱼香肉丝", 20.0, 0),
                new Dishes("红烧带鱼", 10.0, 0),
                new Dishes("时令蔬菜", 10.0, 0)
        };
        this.dishes = dishes;
    }

    /**
     * 菜单1
     */
    void startMenu1() {
        System.out.println("******************************");
        System.out.println("1.我要订餐");
        System.out.println("2.查看餐袋");
        System.out.println("3.签收订单");
        System.out.println("4.删除订单");
        System.out.println("5.我要点赞");
        System.out.println("6.退出系统");
        System.out.println("******************************");

    }

    /**
     * 选择
     *
     * @param a
     */
    void select(int a) {
        switch (a) {
            case 1:
                System.out.println("1.我要订餐");
                break;
            case 2:
                System.out.println("2.查看餐袋");
                break;
            case 3:
                System.out.println("3.签收订单");
                break;
            case 4:
                System.out.println("4.删除订单");
                break;
            case 5:
                System.out.println("5.我要点赞");
                break;
        }
    }

    /*
       查看餐袋
     */
    void display() {
        for (int i = 0; orderingSets[i]!=null; i++) {
            System.out.println("序号 "+(i+1)+orderingSets[i]);
        }
    }

    /**
     * 展示菜品
     */
      void show()
      {
          System.out.println("序号   菜品   单价   点赞数");
          for (int i = 0; i < dishes.length; i++) {
              System.out.println((i+1)+" "+dishes[i]);
          }
      }    /**
     * 增加订单信息
     */
    void add(int i1,int i2,OrderingSet orderingSet){
        i1-=1;
         Dishes dishe= dishes[i1];
           orderingSet.setDishMegs(dishe.getDishesName()+i2+"份");
        orderingSet.setSumPrices(String.valueOf(dishe.getDishesPrice()* i2));
           for(int i = 0; i< orderingSets.length; i++){
              if(orderingSets[i]==null){
                  orderingSets[i]=orderingSet;
                  break;
              }
           }
        System.out.println("您订的是"+orderingSet.getDishMegs());
        System.out.println("送餐时间"+orderingSet.getAddress());
        System.out.print("餐费"+orderingSet.getSumPrices());
        System.out.print(",送餐费0.0元");
        System.out.print(",总计"+orderingSet.getSumPrices());
    }
    /**
     * 签收
     */
    void sign(int a){
        a-=1;
   if(orderingSets[a]==null){
       System.out.println("该订单不存在");
   }
   else
   {
       if(orderingSets[a].getStates().equals("已完成")){

           System.out.println("该订单已签收");
       }
       else{
           orderingSets[a].setStates("已签收");
           System.out.println("该订单签收成功");
       }

   }

    }
    /**
     * 删除
     */
    void delete(int a){
        a-=1;
        if(orderingSets[a]==null){
            System.out.println("该订单不存在");
        }
        else if(orderingSets[a].getStates().equals("已预定")){

            System.out.println("删除失败");
        }
        else
        {
//            System.out.println(a);
            orderingSets[a]=null;
            for(int i = a; i <orderingSets.length-1 ; i++){
                orderingSets[i]=orderingSets[i+1];
            }
            System.out.println("删除成功");
        }
    }

    /**
     * 点赞
     */
     void praise(int a){
         if(dishes[a]!=null){
             int dishedLike = dishes[a - 1].getDishedLike();
             dishes[a - 1].setDishedLike(dishedLike + 1);
             System.out.println("点赞成功");
         }
         else
             System.out.println("点赞失败");

     }
}

